﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.RelatedField", ServerTypeId="{a91deb1a-2f24-4ac5-a1a6-3b1e530c307f}")]
    public class RelatedField : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public RelatedField(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                string str = peekedName;
                if (str == null)
                {
                    return flag;
                }
                if (!(str == "LookupList"))
                {
                    if (str == "WebId")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["WebId"] = reader.ReadGuid();
                        return flag;
                    }
                    if (str == "ListId")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["ListId"] = reader.ReadGuid();
                        return flag;
                    }
                    if (str == "FieldId")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["FieldId"] = reader.ReadGuid();
                        return flag;
                    }
                    if (str == "RelationshipDeleteBehavior")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["RelationshipDeleteBehavior"] = reader.ReadEnum<RelationshipDeleteBehaviorType>();
                    }
                    return flag;
                }
                flag = true;
                reader.ReadName();
                this.LookupList.FromJson(reader);
            }
            return flag;
        }

        [Remote]
        public Guid FieldId
        {
            get
            {
                base.CheckUninitializedProperty("FieldId");
                return (Guid) base.ObjectData.Properties["FieldId"];
            }
        }

        [Remote]
        public Guid ListId
        {
            get
            {
                base.CheckUninitializedProperty("ListId");
                return (Guid) base.ObjectData.Properties["ListId"];
            }
        }

        [Remote]
        public List LookupList
        {
            get
            {
                object obj2;
                if (base.ObjectData.ClientObjectProperties.TryGetValue("LookupList", out obj2))
                {
                    return (List) obj2;
                }
                List list = new List(base.Context, new ObjectPathProperty(base.Context, base.Path, "LookupList"));
                base.ObjectData.ClientObjectProperties["LookupList"] = list;
                return list;
            }
        }

        [Remote]
        public RelationshipDeleteBehaviorType RelationshipDeleteBehavior
        {
            get
            {
                base.CheckUninitializedProperty("RelationshipDeleteBehavior");
                return (RelationshipDeleteBehaviorType) base.ObjectData.Properties["RelationshipDeleteBehavior"];
            }
        }

        [Remote]
        public Guid WebId
        {
            get
            {
                base.CheckUninitializedProperty("WebId");
                return (Guid) base.ObjectData.Properties["WebId"];
            }
        }
    }
}

